package viewmodel;

import java.util.List;

import org.zkoss.bind.BindUtils;
import org.zkoss.bind.annotation.BindingParam;
import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.NotifyChange;
import org.zkoss.zk.ui.util.Clients;

import admin.dao.ExamsDAO;
import admin.dao.UserDAO;

public class ExamsDataVM {
	private List<ExamsEditStatus> examsEditData;
	private boolean displayEdit = true;
	
	public ExamsDataVM() {
		examsEditData = new ExamsDataModel().convertExamsToEditData();
	}
	
	public boolean isDisplayEdit(){
		return displayEdit;
	}

	public List<ExamsEditStatus> getExamsEditData() {
		return examsEditData;
	}

	@Command
	public void changeEditableStatus(@BindingParam("examsEditStatus")ExamsEditStatus ees){
		ees.setEditingStatus(!ees.getEditingStatus());
		refreshRowTemplate(ees);
	}
	@Command
	public void confirm(@BindingParam("examsEditStatus") ExamsEditStatus ees){
		changeEditableStatus(ees);
		ExamsDAO.updateExams(ees);
		refreshRowTemplate(ees);
	}
	@Command
	public void delExam(@BindingParam("examsEditStatus")ExamsEditStatus ees){
		ExamsDAO.removeExams(ees.getExams());
		examsEditData.remove(ees);
		refreshRowTemplate(ees);
	}
	private void refreshRowTemplate(ExamsEditStatus ees) {
		BindUtils.postNotifyChange(null, null, ees, "editingStatus");
	}
	
	
}
